package com.ruoyi.stuclient.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.context.ThirdSessionHolder;
import com.ruoyi.stuclient.domain.EwcHomeworkSubmissionMaterials;
import com.ruoyi.stuclient.domain.dto.HomeworkSubmitDto;
import com.ruoyi.stuclient.mapper.EwcHomeworkSubmissionMaterialsMapper;
import com.ruoyi.stuclient.service.IEwcHomeworkSubmissionMaterialsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.UUID;


/**
 * 作业提交资料Service业务层处理
 * 
 * @author lcj
 * @date 2025-02-28
 */
@Service
public class EwcHomeworkSubmissionMaterialsServiceImpl extends ServiceImpl<EwcHomeworkSubmissionMaterialsMapper, EwcHomeworkSubmissionMaterials> implements IEwcHomeworkSubmissionMaterialsService {


    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean homeworkSubmissionMaterials(HomeworkSubmitDto homeworkSubmitDto) {
        ewcHomeworkSubmissionMaterials.setId(UUID.randomUUID().toString().replace("-", ""));
        ewcHomeworkSubmissionMaterials.setHomeworkSubmissionId(homeworkSubmitDto.getHomeworkSubmissionId());
        ewcHomeworkSubmissionMaterials.setResourceType(homeworkSubmitDto.getResourceType());
        ewcHomeworkSubmissionMaterials.setResourceDescription(homeworkSubmitDto.getResourceDescription());
        ewcHomeworkSubmissionMaterials.setPath(homeworkSubmitDto.getPath());
        ewcHomeworkSubmissionMaterials.setStatus("1");
        ewcHomeworkSubmissionMaterials.setAnalysisId(homeworkSubmitDto.getAnalysisId());
        Date currentDate = new Date();
        ewcHomeworkSubmissionMaterials.setCreateTime(currentDate);
        ewcHomeworkSubmissionMaterials.setUpdateTime(currentDate);
        return save(ewcHomeworkSubmissionMaterials);
    }

    @Override
    public Boolean deleteSubmissionMaterials(String homeworkSubmissionId) {
        QueryWrapper<EwcHomeworkSubmissionMaterials> queryWrapper = new QueryWrapper<>();
        // 根据实体属性设置删除条件
        queryWrapper.eq("homework_submission_id", homeworkSubmissionId);
        // 执行删除操作
        int rows = this.baseMapper.delete(queryWrapper);
        return rows > 0;
    }
}
